package prime;

import static dp.CountSubstrings.isP;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:输出大于或等于n的回文素数
 * author: Mr.Du
 * Date: 2023/4/7
 * Time: 20:16
 */
public class PrimePalindrome {

    public static void main(String[] args) {
        int res = primePalindrome(13);
        System.out.println(res);
    }

    public static int primePalindrome(int n) {
        if(n == 1) return 2;
        for(int i = n;i < 2 * 100000000;i++){
            if(isM(i) && isP(i)){
                return i;
            }
            if (10_000_000 < i && i < 100_000_000)
                i = 100_000_000;
        }
        return -1;
    }

    public static boolean isP(int n){
        for(int i = 2;i <= (int)Math.sqrt(n);i++){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }

    public static boolean isM(int n){
        int sum = 0, x = n, count = 0;
        while(x != 0){
            sum = sum * 10 + x % 10;
            x /= 10;
        }
        return sum == n;
    }
}
